using Llibs.Log;
using UnityEngine;
using YooAsset;

namespace Client.Base
{
    public class Entry : MonoBehaviour
    {
        [SerializeField] private EPlayMode playMode;
        private void Start()
        {
            InitLog();
            InitLocalization();
            StartPatch();
        }

        private void InitLog()
        {
            LogConfig config = new LogConfig
            {
                enableLog = true,
                enableCover = true,
                enableSave = true,
                enableTime = true,
                enableThreadID = false,
                enableTrace = true,
                logPrefix = "",
                loggerEnum = ELoggerType.Unity
            };
#if !UNITY_EDITOR && UNITY_WEBGL
            playMode = EPlayMode.WebPlayMode
            config.enableSave = false;
#elif !UNITY_EDITOR
            playMode = EPlayMode.HostPlayMode;
#endif
            LLog.InitSettings(config);
        }

        private void InitLocalization()
        {
            string lan = Localization.CurLanuage;
            var config = Resources.Load<TextAsset>($"lan_{lan}");
            Localization.SetSource(config.text);
        }
        
        private void StartPatch()
        {
            PatchProcess patch = new PatchProcess(playMode);
            patch.Execute();
        }
    }

}
